<?php
/**
 * +--------------------------------------------------------+
 * @Created by PhpStorm.
 * @Category SchedulingController.php
 * @Depiction:
 * Author: hwy
 * Date: 2020/12/14  14:06
 * +--------------------------------------------------------+
 */

namespace App\Http\Controllers\Admin;

use App\Models\Scheduling;
use Illuminate\Http\Request;

class SchedulingController extends BaseController
{
    public function index(Request $request)
    {
        $compact = compact('request');

        return view('admin.scheduling.index',$compact);

    }

    public function getList(Request $request){
        $responseData = Scheduling::getTasks();

        return response()->json($responseData);
    }

    public function runEvent(Request $request)
    {
        $scheduling = new Scheduling();

        try {
            $output = $scheduling->runTask($request->get('id'));

            return [
                'status'    => true,
                'message'   => '定时任务运行成功',
                'data'      => $output,
            ];
        } catch (\Exception $e) {
            return [
                'status'    => false,
                'message'   => '定时任务运行失败',
                'data'      => $e->getMessage(),
            ];
        }
    }


}
